from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QLineEdit, QPushButton
import sys
import random


class GuessNumber(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.number = random.randint(1, 128)

        self.setGeometry(400, 300, 270, 140)
        self.setWindowTitle("Угадай число")

        self.lablkommit = QLabel('Введи число', self)
        self.lablkommit.move(50, 20)

        self.linedit = QLineEdit(self)
        self.linedit.move(50, 40)
        self.linedit.resize(80, 25)

        self.btn = QPushButton("Проверить", self)
        self.btn.move(140, 40)
        self.btn.resize(90, 25)
        self.btn.clicked.connect(self.run)

        self.lbl_verdict = QLabel(self)
        self.lbl_verdict.move(50, 90)
        self.lbl_verdict.resize(200, 20)
        self.lbl_verdict.setText("Давай угадаю")

    def run(self):
        num = int(self.linedit.text())
        self.linedit.clear()
        if num == self.number:
            self.lbl_verdict.setText("Вы угадали!")
        elif num > self.number:
            self.lbl_verdict.setText("Загаданное число меньше!")
        elif num < self.number:
            self.lbl_verdict.setText("Загаданное число больше!")
        print(num, self.number)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = GuessNumber()
    ex.show()
    sys.exit(app.exec())